package test_0523;

public class test03_insertSort {
    public static void main(String[] args) {
        int[] arr = new int[]{1,5,3,6,4,7,8,10,9,2};
        int len = arr.length - 1;
        for (int i = 0; i <= len; i++) {
            System.out.print(arr[i] +" ");
        }
        int replace_index = 0;//默认初始交换的下标是0
        int tmp  = 0;
        System.out.println();
        for (int i = 0; i < arr.length - 1; i++) {
            replace_index = 0;
            for (int j = 1; j < arr.length - i; j++) {
                if(arr[j] >= arr[replace_index]){
                    replace_index = j;
                }
            }
            tmp = arr[replace_index];
            arr[replace_index] = arr[arr.length - 1 - i];
            arr[arr.length - 1 - i] = tmp;
        }
        for (int i = 0; i <= len ; i++) {
            System.out.print(arr[i] +" ");
        }
    }
}

